#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "index.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}



void MainWindow::on_pushButton_clicked(bool checked)
{
    QSqlQuery query,query1;
    int i=1;
    QString a,p,p1;
    while(i){
        a = ui->lineEdit->text();
        p = ui->lineEdit_2->text();
        if(!(ui->lineEdit->text().isEmpty())&&!(ui->lineEdit_2->text().isEmpty()))
        {
            qDebug()<<"a:     "<<a;
            QString tt = "select Password from dbo.user1 where ID = "+a+";";
            QString ty = "select Password from dbo.guanliyuan where ID = "+a+";";
            qDebug()<<"查询语句:     "<<tt;
            query.prepare(tt);
            if (!query.exec()){

            }
            else
            {
                query.next();
                p1 = query.value(0).toString();
                qDebug()<<"p1:     "<<p1;
                qDebug()<<"p:     "<<p;
                if(p==p1){
                    i=0;
                    index *dd = new index;
                    dd->show();
                    this->close();
                }else
                {
                    query.prepare(ty);
                    if (!query.exec()){
                        QMessageBox::critical(this, "错误", "记录更新错误\n"+query.lastError().text());
                    }
                    query.next();
                    p1 = query.value(0).toString();
                    qDebug()<<"p1:     "<<p1;
                    qDebug()<<"p:     "<<p;
                    if(p==p1){
                        i=0;
                        index *dd = new index;
                        dd->show();
                        this->close();
                    }else
                    {
                        QMessageBox::question(this,
                                              tr("提示"),
                                              tr("账号或密码错误！"),
                                              QMessageBox::Ok | QMessageBox::Cancel,
                                              QMessageBox::Ok);
                        break;
                    }
                    break;
                }
            }
        }else {
            QMessageBox::question(this,
                                  tr("提示"),
                                  tr("账号或密码不能为空！"),
                                  QMessageBox::Ok | QMessageBox::Cancel,
                                  QMessageBox::Ok);
            break;
        }
        break;
    }
}



